<?php
$xh=$_COOKIE['xh'];
$pwd=$_COOKIE['pwd'];
$rememberMe=$_COOKIE['rememberMe'];
if ($_POST){
    try {


        echo '<pre>',print_r($_POST, true),'</pre>';
        if ($_POST['rememberMe']){
            setcookie('xh',$_POST['xh'],time()+7*24*3600);
            setcookie('pwd',$_POST['pwd'],time()+7*24*3600);
            setcookie('rememberMe',$_POST['rememberMe'],time()+7*24*3600);
        }else{
            setcookie('xh');
            setcookie('pwd');
            setcookie('rememberMe');
        }
        $db = new PDO("mysql:host=localhost; dbname=db2;", 'root', '12qwas');
        $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC);
        $ps=$db->prepare('select * from students where xh=? and pwd=?');
        $ps->execute([$_POST['xh'],$_POST['pwd']]);
        $r=$ps->fetch();
        if ($r===false) throw new Exception('你输入的用户口令不正确~');
        header('location: index.php');
        return;
    }catch (Throwable $e){
        $msg=$e->getMessage();
    }

}
?>
